package org.bigdata.framework.core.controller;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.net.FileNameMap;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.SortedMap;
import java.util.TreeMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.bigdata.framework.core.model.Member;
import org.bigdata.framework.core.model.Message;
import org.bigdata.framework.core.model.Online;
import org.bigdata.framework.core.model.Order;
import org.bigdata.framework.core.model.Paper;
import org.bigdata.framework.core.model.ShortFilm;
import org.bigdata.framework.core.model.ShortFilmComment;
import org.bigdata.framework.core.model.User;
import org.bigdata.framework.core.protocol.IBaseService;
import org.bigdata.framework.core.protocol.IPublicService;
import org.bigdata.framework.core.utils.ApiUtils;
import org.bigdata.framework.core.utils.DateUtils;
import org.bigdata.framework.core.utils.IdWorker;
import org.bigdata.framework.core.utils.MD5;
import org.bigdata.framework.core.utils.RandomUtil;
import org.bigdata.framework.core.utils.SignUtil;
import org.bigdata.framework.core.utils.VideoUtil;
import org.bigdata.framework.core.utils.XMLUtil;
import org.bigdata.framework.core.utils.XmlPostUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

import org.apache.commons.lang3.RandomStringUtils;
import org.bigdata.framework.core.log.annotation.SysLog;
import org.bigdata.framework.core.log.enums.BusinessType;
import org.bigdata.framework.core.log.enums.OperatorType;
import org.bigdata.framework.core.model.Advertisement;
import org.bigdata.framework.core.model.Answer;
import org.bigdata.framework.core.model.AnswerVO;
import org.bigdata.framework.core.model.Browse;
import org.bigdata.framework.core.model.Category;
import org.bigdata.framework.core.model.ClassesOnline;
import org.bigdata.framework.core.model.ClassesOnlineComment;
import org.bigdata.framework.core.model.Collect;
import org.bigdata.framework.core.model.Comment;
import org.bigdata.framework.core.model.Config;
import org.bigdata.framework.core.model.Course;
import org.bigdata.framework.core.model.CourseComment;
import org.bigdata.framework.core.model.Live;


/**
 * app对应服务端接口
 * @version
 */
@RestController
@RequestMapping(value="/app-api/*")
public class APIController extends BaseController{

	@Autowired
	private IPublicService publicService;
	@Autowired
	private IBaseService baseService;
	
	private static String FILESERVER = "";
	private static String FILEPATH = "";
	private static String appkey = "";
	private static String pay_url="";
	private static String notify_url="";
	private static String appid="";
	private static String mch_id="";
	private static String trade_type="";
	
	IdWorker idWorker = new IdWorker(2);

	static {
		Properties properties_config = new Properties();
		InputStream in_config = APIController.class.getClassLoader().getResourceAsStream("config.properties");
		try {
			properties_config.load(in_config);

			FILESERVER = properties_config.getProperty("file.server");
			FILEPATH = properties_config.getProperty("file.path");
			appkey = properties_config.getProperty("appkey");
			pay_url = properties_config.getProperty("pay_url");
			notify_url = properties_config.getProperty("notify_url");
			appid = properties_config.getProperty("appid");
			mch_id = properties_config.getProperty("mch_id");
			trade_type = properties_config.getProperty("trade_type");
		} catch (IOException e) {
		}
	}
	
	@RequestMapping(value="/definitions/AnswerVO",method = RequestMethod.POST)
	public AnswerVO defin(){
		return new AnswerVO();
	}	
	
	//注册(参数：手机号+密码)
	@ApiOperation("文件服务器访问地址")
	@RequestMapping(value = "/fileServer", method = RequestMethod.POST)
	public ApiUtils fileServer(HttpServletRequest request) throws Exception{
		return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,FILESERVER);
	}
	//注册(参数：手机号+密码)
    @ApiOperation("注册")
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "telephone", value = "手机号", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "password", value = "密码", paramType = "query", dataType = "string", required = true)
    })
    public ApiUtils register(HttpServletRequest request, @RequestParam String telephone,
                                   @RequestParam String password) throws Exception{
    	  //判断用户是否注册
        HashMap<String, Object> queryParams = new HashMap<String, Object>();
        queryParams.put("=,telephone",telephone);
        List<Member> list = publicService.getMember(queryParams,1,1);
        if(list.size()>0) {
            return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,null);
        }else {
        	Member member = new Member();
        	member.setUsername(telephone);
        	member.setTelephone(telephone);
        	member.setPassword(MD5.convert(password));
        	member.setType(0);
        	member.setStatus(0);
        	member.setCreateTime(DateUtils.getDateTime());
        	Member r = baseService.saveMember(member);
        	r.setPassword(null);
            return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
        }
    }
    //登录（用户名/手机号+密码）
    @ApiOperation("登录")
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名/手机号", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "password", value = "密码", paramType = "query", dataType = "string", required = true),
    })
    public ApiUtils login(@RequestParam String username,@RequestParam String password) throws Exception{
    	
    	Map<String,Object> map = new HashMap<String, Object>();
    	
    	Member r = null;

        //用户名+密码
        HashMap<String, Object> queryParams = new HashMap<String, Object>();
        queryParams.put("=,username",username);
        Integer memberCount = publicService.getMemberCount(queryParams);
        if(memberCount==null || memberCount==0){
        	map.put("result", "fail");
        	map.put("msg", "用户不存在");
        }else{
        	queryParams.put("=,password",MD5.convert(password));
            queryParams.put("=,type",0);
            List<Member> list = publicService.getMember(queryParams,1,1);
            if(list.size()>0) {
                r = list.get(0);
                r.setPassword(null);
                
                map.put("result", "success");
            	map.put("msg", "登录成功");
            	map.put("data",r);
                
                return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,map);
            }else{
            	map.put("result", "error");
            	map.put("msg", "密码不正确");
            }
        }
            //手机号+密码
    	    queryParams = new HashMap<String, Object>();
    	    queryParams.put("=,telephone",username);
    	    memberCount = publicService.getMemberCount(queryParams);
            if(memberCount==null || memberCount==0){
            	map.put("result", "fail");
            	map.put("msg", "用户不存在");
            }else{
            	queryParams.put("=,password",MD5.convert(password));
        	    queryParams.put("=,type",0);
        	    List<Member> list = publicService.getMember(queryParams,1,1);
        	    if(list.size()>0) {
        	        r = list.get(0);
        	        r.setPassword(null);
        	        
        	        map.put("result", "success");
                	map.put("msg", "登录成功");
                	map.put("data",r);
        	        
        	        return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,map);
        	    }else{
        	    	map.put("result", "error");
                	map.put("msg", "密码不正确");
        	    }
            }
    	    
        
            return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,map);
    }
	
	
    //编辑用户信息(头像、昵称、真实姓名、手机号、性别、邮箱、个性签名、简介)
    @ApiOperation("编辑用户信息")
    @RequestMapping(value = "/updateUserInfo", method = RequestMethod.POST)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", value = "用户名/手机号", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "password", value = "密码", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "avatarImg", value = "头像", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "nickName", value = "昵称", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "realName", value = "真实姓名", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "telephone", value = "手机号", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "gender", value = "性别", paramType = "query", dataType = "int", required = false),
            @ApiImplicitParam(name = "email", value = "邮箱", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "signature", value = "个性签名", paramType = "query", dataType = "string", required = false),
            @ApiImplicitParam(name = "description", value = "简介", paramType = "query", dataType = "string", required = false),

    })
    public ApiUtils editUser(@RequestParam(value="username", required=true) String username,
                             @RequestParam(value="password", required=false)  String password,
                             @RequestParam(value="avatarImg", required=false)  String avatarImg,
                             @RequestParam(value="nickName", required=false)  String nickName,
                             @RequestParam(value="realName", required=false)  String realName,
                             @RequestParam(value="telephone", required=false)  String telephone,
                             @RequestParam(value="gender", required=false)  Integer gender,
                             @RequestParam(value="email", required=false)  String email,
                             @RequestParam(value="signature", required=false)  String signature,
                             @RequestParam(value="description", required=false)  String description
                             ) throws Exception{

        //用户名
        HashMap<String, Object> queryParams = new HashMap<String, Object>();
        queryParams.put("=,status",0);
        queryParams.put("=,username",username);
        queryParams.put("=,type",0);
        List<Member> list = publicService.getMember(queryParams,1,1);
        Member member = null;
        if(list.size()>0) {
        	member = list.get(0);
        }
        if(password!=null && !"".equals(password)) {
        	member.setPassword(MD5.convert(password));
        }
        if(avatarImg!=null) {
        	member.setAvatarImg(avatarImg.replace(FILESERVER, "").replace(FILEPATH, "").replace("//", "/"));
        }
        if(nickName!=null) {
        	member.setNickName(nickName);
        }
        if(realName!=null && !"".equals(realName)) {
        	member.setRealName(realName);
        }
        if(telephone!=null && !"".equals(telephone)) {
        	member.setTelephone(telephone);
        }
        if(gender!=null && !"".equals(gender)) {
        	member.setGender(gender);
        }
        if(email!=null) {
        	member.setEmail(email);
        }
        if(description!=null && !"".equals(description)) {
        	member.setDescription(description);
        }
        if(signature!=null && !"".equals(signature)) {
        	member.setSignature(signature);
        }
        Member r =  baseService.editMember(member);
        r.setPassword(null);
        return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //查询用户信息(头像、昵称、真实姓名、手机号、性别、邮箱、个性签名、简介)
    @ApiOperation("查询用户信息")
    @RequestMapping(value = "/findMember", method = RequestMethod.POST)
    @ApiImplicitParams({
    	 @ApiImplicitParam(name = "appKey", value = "appKey", paramType = "query", dataType = "string", required = false),
    	 @ApiImplicitParam(name = "id", value = "前端用户id", paramType = "query", dataType = "string", required = false)
    	
    })
    public ApiUtils editUser(@RequestParam(value="appKey", required=false) String appKey,
    					@RequestParam(value="id", required=false) String id) throws Exception{
    	Map<String,Object>m=new HashMap<String, Object>();
    	if(appKey!=null && !"".equals(appKey)) {
            HashMap<String, Object> queryParams = new HashMap<String, Object>();
            queryParams.put("=,username", appKey.split("&")[0]);
            List<Member> list = publicService.getMember(queryParams, 1, 1);

            if (list.size() > 0) {
            	Member member = list.get(0);
            	m.put("id", member.getId());
    			m.put("avatarImg", member.getAvatarImg());
    			m.put("createTime", member.getCreateTime());
    			m.put("description", member.getDescription());
    			m.put("email", member.getEmail());
    			m.put("gender", member.getGender());
    			m.put("nickName", member.getNickName());
    			m.put("realName", member.getRealName());
    			m.put("signature", member.getSignature());
    			m.put("status", member.getStatus());
    			m.put("telephone", member.getTelephone());
    			m.put("type", member.getType());
    			m.put("username", member.getUsername());
            }
            return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,m);
        }
    	if(id!=null && !"".equals(id)){
    		Member member=publicService.findMember(Integer.parseInt(id));
    		if(member!=null){
    			m.put("id", member.getId());
    			m.put("avatarImg", member.getAvatarImg());
    			m.put("createTime", member.getCreateTime());
    			m.put("description", member.getDescription());
    			m.put("email", member.getEmail());
    			m.put("gender", member.getGender());
    			m.put("nickName", member.getNickName());
    			m.put("realName", member.getRealName());
    			m.put("signature", member.getSignature());
    			m.put("status", member.getStatus());
    			m.put("telephone", member.getTelephone());
    			m.put("type", member.getType());
    			m.put("username", member.getUsername());
    		}
    	}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,m);
    }
    //栏目列表
    @ApiOperation("栏目列表")
    @RequestMapping(value = "/getCategory", method = RequestMethod.POST)
    public ApiUtils getCategory() throws Exception{
    	List<Category> category = publicService.getCategory();
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,category);
    }
    
    //广告列表
    @ApiOperation("广告列表")
    @RequestMapping(value = "/getAdvertisement", method = RequestMethod.POST)
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "type", value = "广告类型（视频/图片）", paramType = "query", dataType = "String", required = false,allowableValues = "图片,视频"),
        	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
        	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
        
    })
    public ApiUtils getAdvertisement(@RequestParam(value="type", required=false) String type,
    								@RequestParam(value="pageNumber", required=true) Integer pageNumber,
    								 @RequestParam(value="pageSize", required=true)  Integer pageSize
            						) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	if(type!=null && !"".equals(type)){
    		queryParams.put("=,type", type);
    	}
    	queryParams.put("=,status", "2");
    	queryParams.put("=,auditType", "2");
    	
    	queryParams.put("<=,startTime", DateUtils.getDateTime());
    	queryParams.put(">=,endTime", DateUtils.getDateTime());
    	
    	Integer count = publicService.getAdvertisementCount(queryParams);
		List<Advertisement> advertisements = publicService.getAdvertisement(queryParams , pageNumber, pageSize);
		List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String,Object>m=null;
		for (Advertisement advertisement : advertisements) {
			m=new HashMap<String, Object>();
			m.put("id", advertisement.getId());
			m.put("createTime", advertisement.getCreateTime());
			m.put("createUser", advertisement.getCreateUser());
			m.put("name", advertisement.getName());
			m.put("startTime", advertisement.getStartTime());
			m.put("endTime", advertisement.getEndTime());
			m.put("status", advertisement.getStatus());
			m.put("submitTime", advertisement.getSubmitTime());
			m.put("type", advertisement.getType());
			m.put("filePath", advertisement.getFilePath());
			m.put("showTime", advertisement.getShowTime());
			m.put("sort", advertisement.getSort());
			m.put("courseId", advertisement.getCourseId());
			Integer courseId = advertisement.getCourseId();
			if(advertisement.getCourseId()!=null && !"".equals(advertisement.getCourseId())){
				Course course = publicService.findCourse(courseId);
				if(course!=null){
					m.put("courseName", course.getName());
				}else{
					m.put("courseName", "");
				}
				course=null;
			}else{
				m.put("courseName", "");
			}
			
			lm.add(m);
			m=null;
		}
		
		Map<String,Object>r=new HashMap<String,Object>();
		r.put("data", lm);
		r.put("count", count);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    
    //课程列表
    @ApiOperation("课程列表")
    @RequestMapping(value = "/getCourse", method = RequestMethod.POST)
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "categoryId", value = "栏目id", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "name", value = "课程名称", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "description", value = "课程描述", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "tag", value = "课程标签", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    		@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    		})
    public ApiUtils getCourse(@RequestParam(value="categoryId", required=false) String categoryId,
    						  @RequestParam(value="name", required=false) String name,
    						  @RequestParam(value="description", required=false) String description,
    						  @RequestParam(value="tag", required=false) String tag,
    						  @RequestParam(value="pageNumber", required=true) Integer pageNumber,
    						  @RequestParam(value="pageSize", required=true)  Integer pageSize
    						  ) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	if(categoryId!=null &&!"".equals(categoryId)){
    		queryParams.put("=,categoryId", categoryId);
    	}
    	if(name!=null &&!"".equals(name)){
    		queryParams.put("%,name", name);
    	}
    	if(description!=null &&!"".equals(description)){
    		queryParams.put("%,description", description);
    	}
    	if(tag!=null &&!"".equals(tag)){
    		queryParams.put("%,tag", tag);
    	}
    	queryParams.put("=,status", "2");
    	queryParams.put("=,auditType", "2");
    	Integer count = publicService.getCourseCount(queryParams);
    	List<Course> courses = publicService.getCourse(queryParams , pageNumber, pageSize);
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String,Object>m=null;
    	for (Course course : courses) {
    		List<Map<String, Object>>sbs=new ArrayList<Map<String,Object>>();
    		if(course.getUserIds()!=null && !"".equals(course.getUserIds())){
    			String[] splits = course.getUserIds().split(";");
    			for (String string : splits) {
    				if(!"".equals(string)){
    					Map<String, Object> sb = new HashMap<String, Object>();
    					User user = publicService.findUser(Integer.parseInt(string));
    					if(user!=null){
    						if(user.getRealName()!=null && !"".equals(user.getRealName())){
        						sb.put("name", user.getRealName());
        					}else{
        						sb.put("name", user.getUsername());
        					}
        					sb.put("avatarImg", user.getAvatarImg());
    						sb.put("description", user.getDescription());
    						sbs.add(sb);
    					}
						sb=null;
    					user=null;
    				}
    			}
    		}
			
			m=new HashMap<String, Object>();
			m.put("id", course.getId());
			m.put("cover", course.getCover());
			m.put("createTime", course.getCreateTime());
			m.put("createUser", course.getCreateUser());
			m.put("description", course.getDescription());
			m.put("grade", course.getGrade());
			m.put("name", course.getName());
			m.put("status", course.getStatus());
			m.put("tag", course.getTag()==null?null:course.getTag().split(";"));
			m.put("userIds", course.getUserIds());
			m.put("teachers", sbs);
			m.put("categoryId", course.getCategoryId());
			Category category = publicService.findCategory(course.getCategoryId());
			if(category!=null){
				m.put("categoryName", category.getName());
			}else{
				m.put("categoryName", "");
			}
			
			
			queryParams=null;
			queryParams=new HashMap<String, Object>();
			queryParams.put("=,courseId", course.getId());
			queryParams.put("=,status", "2");
			queryParams.put("=,auditType", "2");
			Integer onlinecount = publicService.getOnlineCount(queryParams);
			List<Online> onlines = publicService.getOnline(queryParams, 1, onlinecount);
			BigDecimal bigDecimal = new BigDecimal(0);
			if(onlinecount>0){
				for (Online online : onlines) {
					bigDecimal = bigDecimal.add( new BigDecimal(online.getPrice()));
				}
			}
			m.put("price", bigDecimal);
			
			lm.add(m);
			m=null;
			sbs=null;
			category=null;
		}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", count);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //课程详情
    @ApiOperation("课程详情")
    @RequestMapping(value = "/findCourse", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "课程id", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "memberId", value = "用户id，此参数用户判断收藏和订单", paramType = "query", dataType = "string", required = false)
    })
    public ApiUtils findCourse(@RequestParam(value="id", required=true) String id,
    						   @RequestParam(value="memberId", required=false) String memberId
    							) throws Exception{
		Map<String,Object>m=courseDetail(id, memberId);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,m);
    }
    public Map<String,Object> courseDetail(String id,String memberId){
    	Map<String,Object>m=new HashMap<String, Object>();
    	if(id!=null && !"".equals(id)){
			Course course = publicService.findCourse(Integer.parseInt(id));
			if(course!=null){
				List<Map<String, Object>>sbs=new ArrayList<Map<String,Object>>();
				if(course.getUserIds()!=null && !"".equals(course.getUserIds())){
					String[] splits = course.getUserIds().split(";");
					for (String string : splits) {
						if(!"".equals(string)){
							Map<String, Object> sb = new HashMap<String, Object>();
							User user = publicService.findUser(Integer.parseInt(string));
							if(user!=null){
								if(user.getRealName()!=null && !"".equals(user.getRealName())){
									sb.put("name", user.getRealName());
								}else{
									sb.put("name", user.getUsername());
								}
								sb.put("avatarImg", user.getAvatarImg());
								sb.put("description", user.getDescription());
								sbs.add(sb);
							}
							sb=null;
							user=null;
						}
					}
				}
				
				
				m.put("id", course.getId());
				m.put("cover", course.getCover());
				m.put("createTime", course.getCreateTime());
				m.put("createUser", course.getCreateUser());
				m.put("description", course.getDescription());
				m.put("grade", course.getGrade());
				m.put("name", course.getName());
				m.put("status", course.getStatus());
				m.put("tag", course.getTag()==null?null:course.getTag().split(";"));
				m.put("userIds", course.getUserIds());
				m.put("teachers", sbs);
				m.put("categoryId", course.getCategoryId());
				Category category = publicService.findCategory(course.getCategoryId());
				if(category!=null){
					m.put("categoryName", category.getName());
				}else{
					m.put("categoryName", "");
				}
				
				
				HashMap<String, Object> queryParams = new HashMap<String, Object>();
				queryParams.put("=,courseId", course.getId());
				Integer onlinecount = publicService.getOnlineCount(queryParams);
				List<Online> onlines = publicService.getOnline(queryParams, 1, onlinecount);
				BigDecimal bigDecimal = new BigDecimal(0);
				if(onlinecount>0){
					for (Online online : onlines) {
						bigDecimal=bigDecimal.add( new BigDecimal(online.getPrice()));
					}
				}
				m.put("price", bigDecimal);
				
				//课程是否被购买
				if(memberId!=null && !"".equals(memberId)){
					HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
					queryParams1.put("=,memberId", memberId);
					queryParams1.put("=,resourceId", course.getId());
					queryParams1.put("=,type", "0");
					
					
					Integer collectCount = publicService.getCollectCount(queryParams1 );
					if(collectCount>0){
						m.put("collect", true);
					}else{
						m.put("collect", false);
					}
					queryParams1.put("=,status", "0");
					Integer orderCount = publicService.getOrderCount(queryParams1);
					if(orderCount>0){
						m.put("order", true);
					}else{
						m.put("order", false);
					}
					queryParams1=null;
				}
				
			}
		}
    	return m;
    }
    //课程推荐
    @ApiOperation("课程推荐")
    @RequestMapping(value = "/getCourseRecommended", method = RequestMethod.POST)
    @ApiImplicitParams({})
    public ApiUtils getCourseRecommended() throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	List<Category> categorys = publicService.getCategory();
    	List<Map<String,Object>> lm = new ArrayList<Map<String,Object>>();
    	Map<String,Object>m=null;
    	for (Category category : categorys) {
    		m=new HashMap<String,Object>();
    		queryParams=null;
    		queryParams = new HashMap<String, Object>();
    		queryParams.put("=,categoryId", category.getId());
    		queryParams.put("=,status", "2");
    		queryParams.put("=,auditType", "2");
        	List<Course> courses = publicService.getCourse(queryParams , 1, 2);
        	List<Map<String,Object>>lm2=new ArrayList<Map<String,Object>>();
        	for (Course course : courses) {
        		List<Map<String, Object>>sbs=new ArrayList<Map<String,Object>>();
        		if(course.getUserIds()!=null && !"".equals(course.getUserIds())){
        			String[] splits = course.getUserIds().split(";");
        			for (String string : splits) {
        				if(!"".equals(string)){
        					Map<String, Object> sb = new HashMap<String, Object>();
        					User user = publicService.findUser(Integer.parseInt(string));
        					if(user!=null){
        						if(user.getRealName()!=null && !"".equals(user.getRealName())){
            						sb.put("name", user.getRealName());
            					}else{
            						sb.put("name", user.getUsername());
            					}
            					sb.put("avatarImg", user.getAvatarImg());
        						sb.put("description", user.getDescription());
        						sbs.add(sb);
        					}
    						sb=null;
        					user=null;
        				}
        			}
        		}
        		
        		
        		Map<String,Object>m2=new HashMap<String, Object>();
    			m2.put("id", course.getId());
    			m2.put("cover", course.getCover());
    			m2.put("createTime", course.getCreateTime());
    			m2.put("createUser", course.getCreateUser());
    			m2.put("description", course.getDescription());
    			m2.put("grade", course.getGrade());
    			m2.put("name", course.getName());
    			m2.put("status", course.getStatus());
    			m2.put("tag", course.getTag()==null?null:course.getTag().split(";"));
    			m2.put("userIds", course.getUserIds());
    			m2.put("teachers", sbs);
    			m2.put("categoryId", course.getCategoryId());
    			Category category2 = publicService.findCategory(course.getCategoryId());
    			if(category2!=null){
    				m2.put("categoryName", category2.getName());
    			}else{
    				m2.put("categoryName","");
    			}
        		
    			
    			queryParams=null;
    			queryParams=new HashMap<String, Object>();
    			queryParams.put("=,courseId", course.getId());
    			queryParams.put("=,status", "2");
    			queryParams.put("=,auditType", "2");
    			Integer onlinecount = publicService.getOnlineCount(queryParams);
    			List<Online> onlines = publicService.getOnline(queryParams, 1, onlinecount);
    			BigDecimal bigDecimal = new BigDecimal(0);
    			if(onlinecount>0){
    				for (Online online : onlines) {
    					bigDecimal=bigDecimal.add( new BigDecimal(online.getPrice()));
    				}
    			}
    			m2.put("price", bigDecimal);
    			
    			
    			lm2.add(m2);
    			m2=null;
    			sbs=null;
    			category2=null;
    			
    		}
        	
        	m.put("id", category.getId());
        	m.put("name", category.getName());
        	m.put("data", lm2);
        	lm.add(m);
        	lm2=null;
        	courses=null;
        	m=null;
		}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,lm);
    }
    //短片列表
    @ApiOperation("短片列表")
    @RequestMapping(value = "/getShortFilm", method = RequestMethod.POST)
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "only", value = "Y:只有我的，N：所有的", paramType = "query", dataType = "string", required = false,allowableValues = "Y,N"),
    		@ApiImplicitParam(name = "description", value = "短片描述", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    		@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    		})
    public ApiUtils getShortFilm(@RequestParam(value="only", required=false) String only,
    						     @RequestParam(value="description", required=false) String description,
    							 @RequestParam(value="memberId", required=false) String memberId,
    							 @RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    							 @RequestParam(value="pageSize", required=true)  Integer pageSize
    							 ) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	if("Y".equals(only)){
    		if(memberId!=null && !"".equals(memberId)){
    			queryParams.put("=,memberId", memberId);
    		}
    	}else{
    		queryParams.put("=,status", "1");
    	}
    	if(description!=null &&!"".equals(description)){
    		queryParams.put("%,description", description);
    	}
    	Integer count = publicService.getShortFilmCount(queryParams);
    	List<ShortFilm> ShortFilms = publicService.getShortFilm(queryParams , pageNumber, pageSize);
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String,Object>m=null;
    	for (ShortFilm shortFilm : ShortFilms) {
    		m=new HashMap<String, Object>();
    		m.put("id", shortFilm.getId());
    		m.put("cover", shortFilm.getCover());
    		m.put("createTime", shortFilm.getCreateTime());
    		m.put("description", shortFilm.getDescription());
    		m.put("filePath", shortFilm.getFilePath());
    		m.put("status", shortFilm.getStatus());
    		m.put("telephone", shortFilm.getTelephone());
    		m.put("shareNumber", shortFilm.getShareNumber());
    		
    		//收藏数量
    		HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
			queryParams1.put("=,resourceId", shortFilm.getId());
			queryParams1.put("=,type", "1");
			Integer collectCount = publicService.getCollectCount(queryParams1 );
			m.put("collectNumber", collectCount==null?0:collectCount);
			queryParams1=null;
			collectCount=null;
			
			//评论数量
			queryParams1 = new HashMap<String, Object>();
			queryParams1.put("=,shortFilmId", shortFilm.getId());
			Integer shortFilmCommentCount = publicService.getShortFilmCommentCount(queryParams1);
			m.put("commentNumber", shortFilmCommentCount==null?0:shortFilmCommentCount);
			queryParams1=null;
			shortFilmCommentCount=null;
			
    		String memberId2 = shortFilm.getMemberId();
    		m.put("memberId", memberId2);
    		if(memberId2!=null && !"".equals(memberId2)){
    			Member member = publicService.findMember(Integer.parseInt(memberId2));
    			if(member!=null){
    				if(member.getRealName()!=null && !"".equals(member.getRealName())){
        				m.put("memberName", member.getRealName());
        			}else{
        				m.put("memberName", member.getUsername());
        			}
    				m.put("memberCover", member.getAvatarImg());
    			}else{
    				m.put("memberName", "");
    			}
    			member=null;
    			
    			if(memberId!=null && !"".equals(memberId)){
    				//收藏
        			queryParams1 = new HashMap<String, Object>();
    				queryParams1.put("=,memberId", memberId);
    				queryParams1.put("=,resourceId", shortFilm.getId());
    				queryParams1.put("=,type", "1");
    				collectCount = publicService.getCollectCount(queryParams1 );
    				if(collectCount>0){
    					m.put("collect", true);
    				}else{
    					m.put("collect", false);
    				}
    				queryParams1=null;
    				collectCount=null;
    			}
    		}else{
    			m.put("memberName", "");
    		}
    		
    		lm.add(m);
    		m=null;
		}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", count);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //短片列表
    @ApiOperation("短片详情")
    @RequestMapping(value = "/findShortFilm", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "短片id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "string", required = false)
    })
    public ApiUtils findhortFilm(@RequestParam(value="id", required=true) Integer id,
    		@RequestParam(value="memberId", required=false) String memberId
    		) throws Exception{
    	
    	ShortFilm shortFilm = publicService.findShortFilm(id);
    	
    	Map<String,Object>m=new HashMap<String, Object>();
		m.put("id", shortFilm.getId());
		m.put("cover", shortFilm.getCover());
		m.put("createTime", shortFilm.getCreateTime());
		m.put("description", shortFilm.getDescription());
		m.put("filePath", shortFilm.getFilePath());
		m.put("status", shortFilm.getStatus());
		m.put("telephone", shortFilm.getTelephone());
		m.put("shareNumber", shortFilm.getShareNumber());
		
		//收藏数量
		HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
		queryParams1.put("=,resourceId", shortFilm.getId());
		queryParams1.put("=,type", "1");
		Integer collectCount = publicService.getCollectCount(queryParams1 );
		m.put("collectNumber", collectCount==null?0:collectCount);
		queryParams1=null;
		collectCount=null;
		
		//评论数量
		queryParams1 = new HashMap<String, Object>();
		queryParams1.put("=,shortFilmId", shortFilm.getId());
		Integer shortFilmCommentCount = publicService.getShortFilmCommentCount(queryParams1);
		m.put("commentNumber", shortFilmCommentCount==null?0:shortFilmCommentCount);
		queryParams1=null;
		shortFilmCommentCount=null;
		
		String memberId2 = shortFilm.getMemberId();
		m.put("memberId", memberId2);
		if(memberId2!=null && !"".equals(memberId2)){
			Member member = publicService.findMember(Integer.parseInt(memberId2));
			if(member!=null){
				if(member.getRealName()!=null && !"".equals(member.getRealName())){
					m.put("memberName", member.getRealName());
				}else{
					m.put("memberName", member.getUsername());
				}
				m.put("memberCover", member.getAvatarImg());
			}else{
				m.put("memberName", "");
			}
			member=null;
			
			if(memberId!=null && !"".equals(memberId)){
				//收藏
				queryParams1 = new HashMap<String, Object>();
				queryParams1.put("=,memberId", memberId);
				queryParams1.put("=,resourceId", shortFilm.getId());
				queryParams1.put("=,type", "1");
				collectCount = publicService.getCollectCount(queryParams1 );
				if(collectCount>0){
					m.put("collect", true);
				}else{
					m.put("collect", false);
				}
				queryParams1=null;
				collectCount=null;
			}
		}else{
			m.put("memberName", "");
		}
    		
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,m);
    }
    //短片列表
    @ApiOperation("随机短片列表")
    @RequestMapping(value = "/getRandomShortFilm", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "String", required = false),
    	@ApiImplicitParam(name = "pageSize", value = "随机数量", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getRandomShortFilm(
    		@RequestParam(value="memberId", required=false) String memberId,
    		@RequestParam(value="pageSize", required=true)  Integer pageSize
    		) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("=,status", "1");
    	
    	List<Integer>list=new ArrayList<Integer>();
    	Integer count = publicService.getShortFilmCount(queryParams);
		getRandom10(list, 1, count);
		List<ShortFilm> ShortFilms =new ArrayList<ShortFilm>();
		
		for (Integer i : list) {
			List<ShortFilm> shortFilm = publicService.getShortFilm(queryParams , i, 1);
			if(shortFilm!=null && shortFilm.size()>0){
				ShortFilms.add(shortFilm.get(0));
			}
			shortFilm=null;
		}
    	
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
    	Map<String,Object>m=null;
    	for (ShortFilm shortFilm : ShortFilms) {
    		m=new HashMap<String, Object>();
    		m.put("id", shortFilm.getId());
    		m.put("cover", shortFilm.getCover());
    		m.put("createTime", shortFilm.getCreateTime());
    		m.put("description", shortFilm.getDescription());
    		m.put("filePath", shortFilm.getFilePath());
    		m.put("status", shortFilm.getStatus());
    		m.put("telephone", shortFilm.getTelephone());
    		m.put("shareNumber", shortFilm.getShareNumber());
    		
    		//收藏数量
    		HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
    		queryParams1.put("=,resourceId", shortFilm.getId());
    		queryParams1.put("=,type", "1");
    		Integer collectCount = publicService.getCollectCount(queryParams1 );
    		m.put("collectNumber", collectCount==null?0:collectCount);
    		queryParams1=null;
    		collectCount=null;
    		
    		//评论数量
    		queryParams1 = new HashMap<String, Object>();
    		queryParams1.put("=,shortFilmId", shortFilm.getId());
    		Integer shortFilmCommentCount = publicService.getShortFilmCommentCount(queryParams1);
    		m.put("commentNumber", shortFilmCommentCount==null?0:shortFilmCommentCount);
    		queryParams1=null;
    		shortFilmCommentCount=null;
    		
    		String memberId2 = shortFilm.getMemberId();
    		m.put("memberId", memberId2);
    		if(memberId2!=null && !"".equals(memberId2)){
    			Member member = publicService.findMember(Integer.parseInt(memberId2));
    			if(member!=null){
    				if(member.getRealName()!=null && !"".equals(member.getRealName())){
    					m.put("memberName", member.getRealName());
    				}else{
    					m.put("memberName", member.getUsername());
    				}
    				m.put("memberCover", member.getAvatarImg());
    			}else{
    				m.put("memberName", "");
    			}
    			member=null;
    			
    			if(memberId!=null && !"".equals(memberId)){
    				//收藏
    				queryParams1 = new HashMap<String, Object>();
    				queryParams1.put("=,memberId", memberId);
    				queryParams1.put("=,resourceId", shortFilm.getId());
    				queryParams1.put("=,type", "1");
    				collectCount = publicService.getCollectCount(queryParams1 );
    				if(collectCount>0){
    					m.put("collect", true);
    				}else{
    					m.put("collect", false);
    				}
    				queryParams1=null;
    				collectCount=null;
    			}
    		}else{
    			m.put("memberName", "");
    		}
    		
    		lm.add(m);
    		m=null;
    	}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", count);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
   public Map<String, Object> shortFilmDetail(String id,String memberId){
	   ShortFilm shortFilm=publicService.findShortFilm(Integer.parseInt(id));
	   Map<String, Object> m=new HashMap<String, Object>();
		m.put("id", shortFilm.getId());
		m.put("cover", shortFilm.getCover());
		m.put("createTime", shortFilm.getCreateTime());
		m.put("description", shortFilm.getDescription());
		m.put("filePath", shortFilm.getFilePath());
		m.put("status", shortFilm.getStatus());
		m.put("telephone", shortFilm.getTelephone());
		
		String memberId2 = shortFilm.getMemberId();
		m.put("memberId", memberId2);
		if(memberId2!=null && !"".equals(memberId2)){
			Member member = publicService.findMember(Integer.parseInt(memberId2));
			if(member!=null){
				if(member.getRealName()!=null && !"".equals(member.getRealName())){
   				m.put("memberName", member.getRealName());
   			}else{
   				m.put("memberName", member.getUsername());
   			}
				m.put("memberCover", member.getAvatarImg());
			}else{
				m.put("memberName", "");
			}
			member=null;
			
			if(memberId!=null && !"".equals(memberId)){
				//收藏
   			HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
				queryParams1.put("=,memberId", memberId);
				queryParams1.put("=,resourceId", shortFilm.getId());
				queryParams1.put("=,type", "1");
				Integer collectCount = publicService.getCollectCount(queryParams1 );
				if(collectCount>0){
					m.put("collect", true);
				}else{
					m.put("collect", false);
				}
				queryParams1=null;
			}
		}else{
			m.put("memberName", "");
		}
		return m;
   }
    //发布短片
    @ApiOperation("发布短片")
    @RequestMapping(value = "/saveShortFilm", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "String", required = true),
    	@ApiImplicitParam(name = "filePath", value = "文件路径（存储相对路径）", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "cover", value = "封面", paramType = "query", dataType = "String", required = true),
    	@ApiImplicitParam(name = "telephone", value = "手机号", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "description", value = "描述", paramType = "query", dataType = "string", required = true),
    })
    public ApiUtils saveShortFilm(@RequestParam(value="memberId", required=true) String memberId,
    							@RequestParam(value="filePath", required=true)  String filePath,
    							@RequestParam(value="cover", required=true)  String cover,
    							@RequestParam(value="telephone", required=true)  String telephone,
    							@RequestParam(value="description", required=true)  String description
    							) throws Exception{

    	ShortFilm shortFilm = new ShortFilm();
    	shortFilm.setCover(cover==null?null:cover.replace(FILEPATH, "").replace(FILESERVER, ""));
    	shortFilm.setFilePath(filePath==null?null:filePath.replace(FILEPATH, "").replace(FILESERVER, ""));
    	shortFilm.setCreateTime(DateUtils.getDateTime());
    	shortFilm.setDescription(description);
    	shortFilm.setMemberId(memberId);
    	shortFilm.setStatus(0);
    	shortFilm.setTelephone(telephone);
    	ShortFilm editShortFilm = baseService.saveShortFilm(shortFilm);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,editShortFilm);
    }
    //网班列表
    @ApiOperation("网班列表")
    @RequestMapping(value = "/getClassesOnline", method = RequestMethod.POST)
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "name", value = "网班名称", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "description", value = "网班描述", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "tag", value = "网班标签", paramType = "query", dataType = "string", required = false),
    		@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    		@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    		})
    public ApiUtils getClassesOnline(
									@RequestParam(value="name", required=false) String name,
									@RequestParam(value="description", required=false) String description,
									@RequestParam(value="tag", required=false) String tag,
									@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    								@RequestParam(value="pageSize", required=true)  Integer pageSize
    								 ) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	if(name!=null &&!"".equals(name)){
    		queryParams.put("%,name", name);
    	}
    	if(description!=null &&!"".equals(description)){
    		queryParams.put("%,description", description);
    	}
    	if(tag!=null &&!"".equals(tag)){
    		queryParams.put("%,tag", tag);
    	}
    	queryParams.put("=,status", "2");
    	queryParams.put("=,auditType", "2");
    	Integer count = publicService.getClassesOnlineCount(queryParams);
    	List<ClassesOnline> classesOnlines = publicService.getClassesOnline(queryParams , pageNumber, pageSize);
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
    	Map<String,Object>m=null;
    	for (ClassesOnline classesOnline : classesOnlines) {
    		m=new HashMap<String, Object>();
    		
    		m.put("id", classesOnline.getId());
    		m.put("cover", classesOnline.getCover());
    		m.put("createTime", classesOnline.getCreateTime());
    		m.put("createUser", classesOnline.getCreateUser());
    		m.put("description", classesOnline.getDescription());
    		m.put("name", classesOnline.getName());
    		m.put("status", classesOnline.getStatus());
    		m.put("tag", classesOnline.getTag()==null?null:classesOnline.getTag().split(";"));
    		
    		List<Map<String, Object>>sbs=new ArrayList<Map<String,Object>>();
    		if(classesOnline.getUserIds()!=null && !"".equals(classesOnline.getUserIds())){
    			String[] splits = classesOnline.getUserIds().split(";");
    			for (String string : splits) {
    				if(!"".equals(string)){
    					Map<String, Object> sb = new HashMap<String, Object>();
    					User user = publicService.findUser(Integer.parseInt(string));
    					if(user!=null){
    						if(user.getRealName()!=null && !"".equals(user.getRealName())){
        						sb.put("name", user.getRealName());
        					}else{
        						sb.put("name", user.getUsername());
        					}
        					sb.put("avatarImg", user.getAvatarImg());
    						sb.put("description", user.getDescription());
    						sbs.add(sb);
    					}
    					user=null;
    				}
    			}
    		}
			m.put("userIds", classesOnline.getUserIds());
			m.put("teachers", sbs);
    		lm.add(m);
    		m=null;
    		sbs=null;
		}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", count);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //网班详情
    @ApiOperation("网班详情")
    @RequestMapping(value = "/findClassesOnline", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "网班id", paramType = "query", dataType = "String", required = true),
    	@ApiImplicitParam(name = "memberId", value = "用户id(此参数用于判断否收藏或购买)", paramType = "query", dataType = "string", required = false)
    })
    public ApiUtils findClassesOnline(@RequestParam(value="id", required=true)  String id,
    								@RequestParam(value="memberId", required=false) String memberId) throws Exception{
    	
    	Map<String, Object> m = classesOnlineDetail(id, memberId);
    		
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,m);
    }
    public Map<String,Object> classesOnlineDetail(String id,String memberId){
    	Map<String,Object>m=new HashMap<String, Object>();
    	if(id!=null && !"".equals(id)){
    		ClassesOnline classesOnline = publicService.findClassesOnline(Integer.parseInt(id));
    		if(classesOnline!=null){
    			m.put("id", classesOnline.getId());
    			m.put("cover", classesOnline.getCover());
    			m.put("createTime", classesOnline.getCreateTime());
    			m.put("createUser", classesOnline.getCreateUser());
    			m.put("description", classesOnline.getDescription());
    			m.put("name", classesOnline.getName());
    			m.put("status", classesOnline.getStatus());
    			m.put("tag", classesOnline.getTag()==null?null:classesOnline.getTag().split(";"));
    			
    			List<Map<String, Object>>sbs=new ArrayList<Map<String,Object>>();
    			if(classesOnline.getUserIds()!=null && !"".equals(classesOnline.getUserIds())){
    				String[] splits = classesOnline.getUserIds().split(";");
    				for (String string : splits) {
    					if(!"".equals(string)){
    						Map<String, Object> sb = new HashMap<String, Object>();
    						User user = publicService.findUser(Integer.parseInt(string));
    						if(user!=null){
    							if(user.getRealName()!=null && !"".equals(user.getRealName())){
    								sb.put("name", user.getRealName());
    							}else{
    								sb.put("name", user.getUsername());
    							}
    							sb.put("avatarImg", user.getAvatarImg());
    							sb.put("description", user.getDescription());
    							sbs.add(sb);
    						}
    						user=null;
    					}
    				}
    			}
    			
    			m.put("userIds", classesOnline.getUserIds());
    			m.put("teachers", sbs);
    			
    			//课程是否被收藏
				if(memberId!=null && !"".equals(memberId)){
					HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
					queryParams1.put("=,memberId", memberId);
					queryParams1.put("=,resourceId", classesOnline.getId());
					queryParams1.put("=,type", "2");
					
					Integer collectCount = publicService.getCollectCount(queryParams1 );
					if(collectCount>0){
						m.put("collect", true);
					}else{
						m.put("collect", false);
					}
					queryParams1=null;
				}
    			
    		}
    	}
    	return m;
    }
    //修改直播状态
    @ApiOperation("直播列表")
    @RequestMapping(value = "/updateLiveStatus", method = RequestMethod.POST)
    @ApiImplicitParams({
    		@ApiImplicitParam(name = "id", value = "直播id", paramType = "query", dataType = "string", required = true),
    		@ApiImplicitParam(name = "liveStatus", value = "直播状态(0：未直播，1：直播中)", paramType = "query", dataType = "string", required = true,allowableValues = "0,1")
    })
    public ApiUtils getLive(@RequestParam(value="id", required=true) String id,
    						@RequestParam(value="liveStatus", required=true) String liveStatus
    						) throws Exception{
    	Live live = publicService.findLive(Integer.parseInt(id));
    	if(live!=null){
    		live.setLiveStatus(liveStatus);
    		Live editLive = baseService.editLive(live);
    		return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,editLive);
    	}else{
    		return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,null);
    	}
    	
    }
    //修改直播状态
    @ApiOperation("直播列表")
    @RequestMapping(value = "/getLive", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "classesOnlineId", value = "网班id", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "memberId", value = "用户id(此参数用于判断否收藏或购买)", paramType = "query", dataType = "string", required = false),
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getLive(@RequestParam(value="classesOnlineId", required=true) String classesOnlineId,
    		@RequestParam(value="memberId", required=false) String memberId,
    		@RequestParam(value="pageNumber", required=true) Integer pageNumber,
    		@RequestParam(value="pageSize", required=true) Integer pageSize
    		) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,classesOnlineId", classesOnlineId);
    	queryParams.put("=,status", "2");
    	queryParams.put("=,auditType", "2");
    	Integer count = publicService.getLiveCount(queryParams);
    	List<Live> lives = publicService.getLive(queryParams , pageNumber, pageSize);
    	
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
    	Map<String,Object>m=null;
    	for (Live live : lives) {
    		m= new HashMap<String, Object>();
    		m.put("id", live.getId());
    		m.put("cover", live.getCover());
    		m.put("createTime", live.getCreateTime());
    		m.put("createUser", live.getCreateUser());
    		m.put("description", live.getDescription());
    		m.put("liveEnd", live.getLiveEnd());
    		m.put("liveSource", live.getLiveSource());
    		m.put("liveStart", live.getLiveStart());
    		m.put("name", live.getName());
    		m.put("price", live.getPrice());
    		m.put("status", live.getStatus());
    		m.put("liveStatus", live.getLiveStatus());
    		m.put("tag", live.getTag()==null?null:live.getTag().split(";"));
    		if(live.getClassesOnlineId()!=null && !"".equals(live.getClassesOnlineId())){
    			ClassesOnline classesOnline = publicService.findClassesOnline(live.getClassesOnlineId());
    			if(classesOnline!=null){
    				m.put("classesOnlineId", classesOnline.getId());
    				m.put("classesOnlineName", classesOnline.getName());
    				classesOnline=null;
    			}else{
    				m.put("classesOnlineId", "");
    				m.put("classesOnlineName", "");
    			}
    		}else{
    			m.put("classesOnlineId", "");
    			m.put("classesOnlineName", "");
    		}
    		
    		
    		//直播是否被购买
    		if(memberId!=null && !"".equals(memberId)){
    			HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
    			queryParams1.put("=,memberId", memberId);
    			queryParams1.put("=,resourceId", live.getId());
    			queryParams1.put("=,type", "2");
    			queryParams1.put("=,status", "0");
    			
    			Integer orderCount = publicService.getOrderCount(queryParams1 );
    			if(orderCount>0){
    				m.put("order", true);
    			}else{
    				m.put("order", false);
    			}
    			queryParams1=null;
    		}
    		
    		
    		lm.add(m);
    		m=null;
    	}
    	
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", count);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    
    //直播详情
    @ApiOperation("直播详情")
    @RequestMapping(value = "/findLive", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "直播id", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "memberId", value = "用户id(此参数用于判断否收藏或购买)", paramType = "query", dataType = "string", required = false)
    })
    public ApiUtils findLive(@RequestParam(value="id", required=true) String id,
    						@RequestParam(value="memberId", required=false) String memberId) throws Exception{
    	
    	Map<String,Object>m= liveDetail(id, memberId);
    	
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,m);
    }
    public Map<String,Object> liveDetail(String id,String memberId){
    	Map<String,Object>m= new HashMap<String, Object>();
    	if(id!=null && !"".equals(id)){
    		Live live = publicService.findLive(Integer.parseInt(id));
    		if(live!=null){
    			m.put("id", live.getId());
    			m.put("cover", live.getCover());
    			m.put("createTime", live.getCreateTime());
    			m.put("createUser", live.getCreateUser());
    			m.put("description", live.getDescription());
    			m.put("liveEnd", live.getLiveEnd());
    			m.put("liveSource", live.getLiveSource());
    			m.put("liveStart", live.getLiveStart());
    			m.put("name", live.getName());
    			m.put("price", live.getPrice());
    			m.put("status", live.getStatus());
    			m.put("tag", live.getTag()==null?null:live.getTag().split(";"));
    			if(live.getClassesOnlineId()!=null && !"".equals(live.getClassesOnlineId())){
    				ClassesOnline classesOnline = publicService.findClassesOnline(live.getClassesOnlineId());
    				m.put("classesOnlineId", classesOnline.getId());
    				m.put("classesOnlineName", classesOnline.getName());
    				classesOnline=null;
    			}else{
    				m.put("classesOnlineId", "");
    				m.put("classesOnlineName", "");
    			}
    			//课程是否购买
				if(memberId!=null && !"".equals(memberId)){
					HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
					queryParams1.put("=,memberId", memberId);
					queryParams1.put("=,resourceId", live.getId());
					queryParams1.put("=,type", "2");
					queryParams1.put("=,status", "0");
					
					Integer orderCount = publicService.getOrderCount(queryParams1 );
					if(orderCount>0){
						m.put("order", true);
					}else{
						m.put("order", false);
					}
					queryParams1=null;
				}
    		}
    	}
    	return m;
    }
    //微课列表
    @ApiOperation("微课列表")
    @RequestMapping(value = "/getOnline", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "courseId", value = "课程id", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "memberId", value = "用户id(此参数用于判断否购买)", paramType = "query", dataType = "string", required = false)
    })
    public ApiUtils getOnline(@RequestParam(value="courseId", required=true) String courseId,
    						@RequestParam(value="memberId", required=false) String memberId
    							) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "asc");
    	if(courseId!=null && !"".equals(courseId)){
    		queryParams.put("=,courseId", courseId);
    	}
    	queryParams.put("=,status", "2");
    	queryParams.put("=,auditType", "2");
    	//System.out.println(courseId);
    	Integer count = publicService.getOnlineCount(queryParams);
    	List<Online> onlines = publicService.getOnline(queryParams, 1, count);
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String,Object>m=null;
    	for (Online online : onlines) {
    		m= new HashMap<String, Object>();
    		m.put("id", online.getId());
    		m.put("createTime", online.getCreateTime());
    		m.put("createUser", online.getCreateUser());
    		m.put("description", online.getDescription());
    		m.put("name", online.getName());
    		m.put("pdfPath", online.getPdfPath());
    		m.put("pptPath", online.getPptPath());
    		m.put("price", online.getPrice());
    		m.put("status", online.getStatus());
    		m.put("tag", online.getTag());
    		m.put("type", online.getType());
    		m.put("videoPath", online.getVideoPath());
    		m.put("courseId", online.getCourseId());
    		if(online.getCourseId()!=null && !"".equals(online.getCourseId())){
    			Course course = publicService.findCourse(online.getCourseId());
    			if(course!=null){
    				m.put("courseName", course.getName());
    			}else{
    				m.put("courseName", "");
    			}
    		}else{
    			m.put("courseName", "");
    		}
    		
    		//课程是否被购买
			if(memberId!=null && !"".equals(memberId)){
				HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
				queryParams1.put("=,memberId", memberId);
				queryParams1.put("=,resourceId", online.getId());
				queryParams1.put("=,type", "1");
				queryParams1.put("=,status", "0");
				
				Integer orderCount = publicService.getOrderCount(queryParams1);
				if(orderCount>0){
					m.put("order", true);
				}else{
					m.put("order", false);
				}
				queryParams1=null;
			}
    		lm.add(m);
    		m=null;
    	}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", count);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    public Map<String,Object> onlineDetail(String id,String memberId){
    	Online online=publicService.findOnline(Integer.parseInt(id));
    	Map<String,Object>m = new HashMap<String, Object>();
    	m= new HashMap<String, Object>();
		m.put("id", online.getId());
		m.put("createTime", online.getCreateTime());
		m.put("createUser", online.getCreateUser());
		m.put("description", online.getDescription());
		m.put("name", online.getName());
		m.put("pdfPath", online.getPdfPath());
		m.put("pptPath", online.getPptPath());
		m.put("price", online.getPrice());
		m.put("status", online.getStatus());
		m.put("tag", online.getTag());
		m.put("type", online.getType());
		m.put("videoPath", online.getVideoPath());
		m.put("courseId", online.getCourseId());
		if(online.getCourseId()!=null && !"".equals(online.getCourseId())){
			Course course = publicService.findCourse(online.getCourseId());
			if(course!=null){
				m.put("courseName", course.getName());
				m.put("courseCover", course.getCover());
			}else{
				m.put("courseName", "");
			}
		}else{
			m.put("courseName", "");
		}
		
		//课程是否被购买
		if(memberId!=null && !"".equals(memberId)){
			HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
			queryParams1.put("=,memberId", memberId);
			queryParams1.put("=,resourceId", online.getId());
			queryParams1.put("=,type", "1");
			queryParams1.put("=,status", "0");
			
			Integer orderCount = publicService.getOrderCount(queryParams1);
			if(orderCount>0){
				m.put("order", true);
			}else{
				m.put("order", false);
			}
			queryParams1=null;
		}
		return m;
    }
    //热门搜索
    @ApiOperation("热门搜索")
    @RequestMapping(value = "/getHots", method = RequestMethod.POST)
    @ApiImplicitParams({
		@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
		@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
		})
    public ApiUtils getHots(@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
			 				@RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
		Integer configCount = publicService.getConfigCount(queryParams );
		List<Config> configs = publicService.getConfig(queryParams, pageNumber, pageSize);
		Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", configs);
    	r.put("count", configCount);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //课程评论列表
    @ApiOperation("课程评论列表")
    @RequestMapping(value = "/getCourseComment", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "courseId", value = "课程Id", paramType = "query", dataType = "int", required = true),
		@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
		@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
		})
    public ApiUtils getCourseComment(@RequestParam(value="courseId", required=true)  Integer courseId,
    								@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
			 						 @RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,courseId", courseId);
    	Integer courseCommentCount = publicService.getCourseCommentCount(queryParams);
    	List<CourseComment> courseComments = publicService.getCourseComment(queryParams, pageNumber, pageSize);
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
		Map<String,Object>m=null;
    	for (CourseComment courseComment : courseComments) {
			m=new HashMap<String, Object>();
			m.put("id", courseComment.getId());
			m.put("content", courseComment.getContent());
			m.put("createTime", courseComment.getCreateTime());
			Member member = publicService.findMember(courseComment.getMemberId());
			if(member!=null){
				m.put("username", member.getUsername());
				m.put("avatarimg", member.getAvatarImg());
			}else{
				m.put("username", "佚名");
				m.put("avatarimg","");
			}
			member=null;
			lm.add(m);
			m=null;
		}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", courseCommentCount);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
   
    //短片评论列表
    @ApiOperation("短片评论列表")
    @RequestMapping(value = "/getShortFilmComment", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "shortFilmId", value = "短片id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getShortFilmComment(@RequestParam(value="shortFilmId", required=true)  Integer shortFilmId,
    		@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    		@RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,shortFilmId", shortFilmId);
    	Integer shortFilmCommentCount = publicService.getShortFilmCommentCount(queryParams);
    	List<ShortFilmComment> shortFilmComments = publicService.getShortFilmComment(queryParams, pageNumber, pageSize);
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
    	Map<String,Object>m=null;
    	for (ShortFilmComment shortFilmComment : shortFilmComments) {
    		m=new HashMap<String, Object>();
    		m.put("id", shortFilmComment.getId());
    		m.put("content", shortFilmComment.getContent());
    		m.put("createTime", shortFilmComment.getCreateTime());
    		Member member = publicService.findMember(shortFilmComment.getMemberId());
    		if(member!=null){
				m.put("username", member.getUsername());
				m.put("avatarimg", member.getAvatarImg());
			}else{
				m.put("username", "佚名");
				m.put("avatarimg","");
			}
    		//m.put("username", member.getUsername());
    		//m.put("avatarimg", member.getAvatarImg());
    		member=null;
    		lm.add(m);
    		m=null;
    	}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", shortFilmCommentCount);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    
    //网班评论列表
    @ApiOperation("网班评论列表")
    @RequestMapping(value = "/getClassesOnlineComment", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "classesOnlineId", value = "网班id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getClassesOnlineComment(@RequestParam(value="classesOnlineId", required=true)  Integer classesOnlineId,
    										@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    										@RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,classesOnlineId", classesOnlineId);
    	Integer classesOnlineCommentCount = publicService.getClassesOnlineCommentCount(queryParams);
    	List<ClassesOnlineComment> classesOnlineComments = publicService.getClassesOnlineComment(queryParams, pageNumber, pageSize);
    	List<Map<String,Object>>lm=new ArrayList<Map<String,Object>>();
    	Map<String,Object>m=null;
    	for (ClassesOnlineComment classesOnlineComment : classesOnlineComments) {
    		m=new HashMap<String, Object>();
    		m.put("id", classesOnlineComment.getId());
    		m.put("content", classesOnlineComment.getContent());
    		m.put("createTime", classesOnlineComment.getCreateTime());
    		Member member = publicService.findMember(classesOnlineComment.getMemberId());
    		if(member!=null){
				m.put("username", member.getUsername());
				m.put("avatarimg", member.getAvatarImg());
			}else{
				m.put("username", "佚名");
				m.put("avatarimg","");
			}
    		//m.put("username", member.getUsername());
    		//m.put("avatarimg", member.getAvatarImg());
    		member=null;
    		lm.add(m);
    		m=null;
    	}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", classesOnlineCommentCount);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    
    //添加收藏
    @ApiOperation("添加收藏")
    @RequestMapping(value = "/saveCollect", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "type", value = "资源类型（0-课程 1-短片 2-网班）", paramType = "query", dataType = "string", required = true,allowableValues = "0,1,2"),
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "resourceId", value = "资源ID", paramType = "query", dataType = "int", required = true)
    })
    public ApiUtils saveCollect(@RequestParam(value="type", required=true) String type,
    		@RequestParam(value="memberId", required=true) Integer memberId,
    		@RequestParam(value="resourceId", required=true)  Integer resourceId
    		) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("=,type", type);
    	queryParams.put("=,memberId", memberId);
    	queryParams.put("=,resourceId", resourceId);
    	Integer collectCount = publicService.getCollectCount(queryParams);
    	if(collectCount>0){
    		return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,null);
    	}else{
    		
    		if("1".equals(type)){
    			ShortFilm findShortFilm = publicService.findShortFilm(resourceId);
    			if(findShortFilm!=null){
    				if(findShortFilm.getShareNumber()!=null && !"".equals(findShortFilm.getShareNumber())){
    					findShortFilm.setShareNumber(findShortFilm.getShareNumber()+1);
    				}else{
    					findShortFilm.setShareNumber(1);
    				}
    				baseService.editShortFilm(findShortFilm);
    				findShortFilm=null;
    			}
    		}
    		
    		Collect collect = new Collect();
    		collect.setCreateTime(DateUtils.getDateTime());
    		collect.setMemberId(memberId);
    		collect.setResourceId(resourceId);
    		collect.setType(type);
    		Collect saveCollect = baseService.saveCollect(collect);
    		return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,saveCollect);
    	}
    }
    //删除收藏
    @ApiOperation("删除收藏")
    @RequestMapping(value = "/deleteCollect", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "type", value = "资源类型（0-课程 1-短片 2-网班）", paramType = "query", dataType = "string", required = true,allowableValues = "0,1,2"),
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "resourceId", value = "资源ID", paramType = "query", dataType = "int", required = true)
    })
    public ApiUtils deleteCollect(@RequestParam(value="type", required=true) String type,
    		@RequestParam(value="memberId", required=true) Integer memberId,
    		@RequestParam(value="resourceId", required=true)  Integer resourceId
    		) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("=,type", type);
    	queryParams.put("=,memberId", memberId);
    	queryParams.put("=,resourceId", resourceId);
    	Integer collectCount = publicService.getCollectCount(queryParams);
    	List<Collect> collects = publicService.getCollect(queryParams, 1, collectCount);
    	
    	if("1".equals(type)){
			ShortFilm findShortFilm = publicService.findShortFilm(resourceId);
			if(findShortFilm!=null){
				if(findShortFilm.getShareNumber()!=null && !"".equals(findShortFilm.getShareNumber())&&findShortFilm.getShareNumber()>0){
					findShortFilm.setShareNumber(findShortFilm.getShareNumber()-1);
				}else{
					findShortFilm.setShareNumber(0);
				}
				baseService.editShortFilm(findShortFilm);
				findShortFilm=null;
			}
		}
    	
    	for (Collect collect : collects) {
			baseService.deleteCollect(collect);
		}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,null);
    }
    //添加意见
    @ApiOperation("添加意见")
    @RequestMapping(value = "/saveComment", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "telephone", value = "手机号", paramType = "query", dataType = "string", required = false),
    	@ApiImplicitParam(name = "content", value = "意见内容", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "cover", value = "上传图片", paramType = "query", dataType = "string", required = false),
    	@ApiImplicitParam(name = "contact", value = "联系方式", paramType = "query", dataType = "string", required = false),
    	@ApiImplicitParam(name = "score", value = "评分", paramType = "query", dataType = "string", required = true)
    })
    public ApiUtils saveComment(@RequestParam(value="memberId", required=true)  Integer memberId,
    		@RequestParam(value="telephone", required=false)  String telephone,
    		@RequestParam(value="content", required=true)  String content,
    		@RequestParam(value="cover", required=false)  String cover,
    		@RequestParam(value="contact", required=false)  String contact,
    		@RequestParam(value="score", required=true)  String score
    		) throws Exception{
    	Comment comment = new Comment();
    	comment.setContent(content);
    	comment.setCreateTime(DateUtils.getDateTime());
    	comment.setMemberId(memberId);
    	comment.setTelephone(telephone);
    	comment.setStatus(0);
    	comment.setCover(cover);
    	comment.setContact(contact);
    	comment.setScore(score);
    	Comment saveComment = baseService.saveComment(comment);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,saveComment);
    }
    //添加课程评论
    @ApiOperation("添加课程评论")
    @RequestMapping(value = "/saveCourseComment", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "content", value = "评论内容", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "courseId", value = "课程id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "telephone", value = "手机号", paramType = "query", dataType = "string", required = false)
    })
    public ApiUtils saveCourseComment(@RequestParam(value="memberId", required=true)  Integer memberId,
    		@RequestParam(value="content", required=true)  String content,
    		@RequestParam(value="courseId", required=true)  Integer courseId,
    		@RequestParam(value="telephone", required=false)  String telephone) throws Exception{
    	CourseComment courseComment = new CourseComment();
    	courseComment.setContent(content);
    	courseComment.setCreateTime(DateUtils.getDateTime());
    	courseComment.setMemberId(memberId);
    	courseComment.setCourseId(courseId);
    	CourseComment saveCourseComment = baseService.saveCourseComment(courseComment);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,saveCourseComment);
    }
    //添加网班评论
    @ApiOperation("添加网班评论")
    @RequestMapping(value = "/saveClassesOnlineComment", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "content", value = "评论内容", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "classesOnlineId", value = "网班id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "telephone", value = "手机号", paramType = "query", dataType = "string", required = false)
    })
    public ApiUtils saveClassesOnlineComment(@RequestParam(value="memberId", required=true)  Integer memberId,
    		@RequestParam(value="content", required=true)  String content,
    		@RequestParam(value="classesOnlineId", required=true)  Integer classesOnlineId,
    		@RequestParam(value="telephone", required=false)  String telephone) throws Exception{
    	ClassesOnlineComment classesOnlineComment = new ClassesOnlineComment();
    	classesOnlineComment.setContent(content);
    	classesOnlineComment.setCreateTime(DateUtils.getDateTime());
    	classesOnlineComment.setMemberId(memberId);
    	classesOnlineComment.setClassesOnlineId(classesOnlineId);
    	ClassesOnlineComment saveClassesOnlineComment = baseService.saveClassesOnlineComment(classesOnlineComment);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,saveClassesOnlineComment);
    }
    //添加短片评论
    @ApiOperation("添加短片评论")
    @RequestMapping(value = "/saveShortFilmComment", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "content", value = "评论内容", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "shortFilmId", value = "短片id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "telephone", value = "手机号", paramType = "query", dataType = "string", required = false)
    })
    public ApiUtils saveShortFilmComment(@RequestParam(value="memberId", required=true)  Integer memberId,
    		@RequestParam(value="content", required=true)  String content,
    		@RequestParam(value="shortFilmId", required=true)  Integer shortFilmId,
    		@RequestParam(value="telephone", required=false)  String telephone) throws Exception{
    	ShortFilmComment shortFilmComment = new ShortFilmComment();
    	shortFilmComment.setContent(content);
    	shortFilmComment.setCreateTime(DateUtils.getDateTime());
    	shortFilmComment.setMemberId(memberId);
    	shortFilmComment.setShortFilmId(shortFilmId);
    	ShortFilmComment saveShortFilmComment = baseService.saveShortFilmComment(shortFilmComment);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,saveShortFilmComment);
    }
    //保存答案
    @ApiOperation("保存答案")
    @PostMapping("/saveAnswer")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "answer", value = "答案对象",paramType = "body",  dataType = "AnswerVO", required = true)
    })
    @ResponseBody
    public ApiUtils saveAnswer(@Valid @RequestBody AnswerVO answer) throws Exception{
    	
    	
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
		queryParams.put("=,memberId", answer.getMemberId());
		queryParams.put("=,paperId", answer.getPaperId());
		queryParams.put("=,questionId", answer.getQuestionId());
		Integer answerCount = publicService.getAnswerCount(queryParams);
		if(answerCount==null || answerCount==0){
			Answer answer2 = new Answer();
	    	answer2.setAnswer(answer.getAnswer());
	    	answer2.setCreateTime(DateUtils.getDateTime());
	    	answer2.setMemberId(answer.getMemberId());
	    	answer2.setPaperId(answer.getPaperId());
	    	answer2.setQuestionId(answer.getQuestionId());
	    	Answer saveAnswer = baseService.saveAnswer(answer2);
		}else{
			List<Answer> answers2 = publicService.getAnswer(queryParams,1,1);
			Answer answer2 = answers2.get(0);
			answer2.setAnswer(answer.getAnswer());
	    	answer2.setCreateTime(DateUtils.getDateTime());
	    	answer2.setMemberId(answer.getMemberId());
	    	answer2.setPaperId(answer.getPaperId());
	    	answer2.setQuestionId(answer.getQuestionId());
	    	Answer saveAnswer = baseService.editAnswer(answer2);
		}
		Map<String,Object>r=new HashMap<String,Object>();
    	
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,null);
    }

    //保存答案集合
    @ApiOperation("保存答案集合")
    @PostMapping(value="/saveAnswerAll")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "answers", value = "答案集合",paramType = "body",  allowMultiple = true, dataType = "AnswerVO", required = true)
    })
    @ResponseBody
    public ApiUtils saveAnswerAll(@Valid @RequestBody List<AnswerVO> answers) throws Exception{
    	HashMap<String, Object> queryParams = null;
    	for (AnswerVO answer : answers) {
    		queryParams = new HashMap<String, Object>();
    		queryParams.put("=,memberId", answer.getMemberId());
    		queryParams.put("=,paperId", answer.getPaperId());
    		queryParams.put("=,questionId", answer.getQuestionId());
			Integer answerCount = publicService.getAnswerCount(queryParams);
			if(answerCount>0){
				List<Answer> answers2 = publicService.getAnswer(queryParams,1,1);
				Answer answer2 = answers2.get(0);
				answer2.setAnswer(answer.getAnswer());
	        	answer2.setCreateTime(DateUtils.getDateTime());
	        	answer2.setMemberId(answer.getMemberId());
	        	answer2.setPaperId(answer.getPaperId());
	        	answer2.setQuestionId(answer.getQuestionId());
	        	baseService.editAnswer(answer2);
			}else{
				Answer answer2 = new Answer();
	        	answer2.setAnswer(answer.getAnswer());
	        	answer2.setCreateTime(DateUtils.getDateTime());
	        	answer2.setMemberId(answer.getMemberId());
	        	answer2.setPaperId(answer.getPaperId());
	        	answer2.setQuestionId(answer.getQuestionId());
	        	baseService.saveAnswer(answer2);
			}
			queryParams=null;
			answerCount=null;
		}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,null);
    }
    //试卷列表
    @ApiOperation("试卷列表")
    @RequestMapping(value = "/getPaper", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "type", value = "试卷类型（0课程，1微课，2直播）", paramType = "query", dataType = "string", required = true,allowableValues = "0,1,2"),
    	@ApiImplicitParam(name = "resourceId", value = "资源id（课程或微课或直播的id）", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getPaper(@RequestParam(value="type", required=true)  String type,
    		@RequestParam(value="resourceId", required=true)  String resourceId,
    		@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    		@RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,type", type);
    	queryParams.put("=,resourceId", resourceId);
    	
		Integer paperCount = publicService.getPaperCount(queryParams);
		List<Paper> papers = publicService.getPaper(queryParams, pageNumber, pageSize);
		
		Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", papers);
    	r.put("count", paperCount);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //试卷题目列表
    @ApiOperation("试卷题目列表")
    @RequestMapping(value = "/getPaperQuestion", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "type", value = "试卷类型（0课程，1微课，2直播）", paramType = "query", dataType = "string", required = true,allowableValues = "0,1,2"),
    	@ApiImplicitParam(name = "paperId", value = "试卷id", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "memberId", value = "用户id(用于判断改试卷题目是否做过)", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getPaperQuestion(@RequestParam(value="type", required=true)  String type,
    		@RequestParam(value="paperId", required=true)  String paperId,
    		@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    		@RequestParam(value="pageSize", required=true)  Integer pageSize,
    		@RequestParam(value="memberId", required=true)  Integer memberId) throws Exception{
    	
    	Integer count=0;
    	List<Map<String, Object>> lm = new ArrayList<Map<String,Object>>();
    	if("0".equals(type)){
    		count = publicService.getCourseQuestionListCount(paperId);
        	lm = publicService.getCourseQuestionList(paperId, pageNumber, pageSize);
    	}else if("1".equals(type)){
    		count = publicService.getOnlineQuestionListCount(paperId);
        	lm = publicService.getOnlineQuestionList(paperId, pageNumber, pageSize);
    	}else if("2".equals(type)){
    		count = publicService.getLiveQuestionListCount(paperId);
        	lm = publicService.getLiveQuestionList(paperId, pageNumber, pageSize);
    	}
    	HashMap<String, Object> queryParams = null;
    	for (Map<String, Object> map : lm) {
    		queryParams = new HashMap<String, Object>();
    		queryParams.put("=,memberId", memberId);
    		queryParams.put("=,paperId", paperId);
    		queryParams.put("=,questionId", map.get("questionId"));
			List<Answer> answer = publicService.getAnswer(queryParams,1,1); 
			if(answer!=null && answer.size()>0){
				map.put("yourAnswer", answer.get(0).getAnswer());
			}
			answer=null;
		}
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("data", lm);
    	r.put("count", count);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //返回收藏列表
    @ApiOperation("收藏列表")
    @RequestMapping(value = "/getCollect", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "type", value = "资源类型（0-课程 1-短片 2-网班）", paramType = "query", dataType = "string", required = false,allowableValues = "0,1,2"),
    	@ApiImplicitParam(name = "memberId", value = "用户ID", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getCollect(@RequestParam(value="type", required=false)  String type,
    							@RequestParam(value="memberId", required=true)  Integer memberId,
    							@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    							@RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,memberId", memberId);
    	if(type!=null && !"".equals(type)){
    		queryParams.put("=,type", type);
    	}
		Integer collectCount = publicService.getCollectCount(queryParams);
		List<Collect> collects = publicService.getCollect(queryParams, pageNumber, pageSize);
		List<Map<String,Object>> lm = new ArrayList<Map<String,Object>>();
		Map<String,Object> m = null;
		for (Collect collect : collects) {
			m=new HashMap<String, Object>();
			m.put("id", collect.getId());
			m.put("createTime", collect.getCreateTime());
			m.put("memberId", collect.getMemberId());
			m.put("type", collect.getType());
			m.put("resourceId", collect.getResourceId());
			if("0".equals(collect.getType())){
				//课程
				Map<String,Object>m1=courseDetail(String.valueOf(collect.getResourceId()), String.valueOf(memberId));
				m.put("course", m1);
				m1=null;
			}else if("1".equals(collect.getType())){
				//短片
				Map<String, Object> m1 = shortFilmDetail(String.valueOf(collect.getResourceId()), String.valueOf(memberId));
				m.put("shortFilm", m1);
				m1=null;
			}else if("2".equals(collect.getType())){
				//网班
				Map<String, Object> m1 = classesOnlineDetail(String.valueOf(collect.getResourceId()), String.valueOf(memberId));
				m.put("clasesOnline", m1);
				m1=null;
			}
			lm.add(m);
			m=null;
		}
    	
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("count", collectCount);
    	r.put("data", lm);
    	lm=null;
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    
    //返回订单列表
    @ApiOperation("订单列表")
    @RequestMapping(value = "/getOrder", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户ID", paramType = "query", dataType = "string", required = true),
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getOrder(@RequestParam(value="memberId", required=true)  Integer memberId,
    		@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    		@RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,memberId", memberId);
    	Integer orderCount = publicService.getOrderCount(queryParams);
    	List<Order> orders = publicService.getOrder(queryParams, pageNumber, pageSize);
    	List<Map<String,Object>> lm = new ArrayList<Map<String,Object>>();
    	Map<String,Object> m = null;
    	for (Order order : orders) {
    		m=new HashMap<String, Object>();
    		m.put("id", order.getId());
    		m.put("createTime", order.getCreateTime());
    		m.put("memberId", order.getMemberId());
    		m.put("type", order.getType());
    		m.put("resourceId", order.getResourceId());
    		m.put("orderNumber", order.getOrderNumber());
    		m.put("payPrice", order.getPayPrice());
    		m.put("payWay", order.getPayWay());
    		m.put("status", order.getStatus());
    		
    		if(order.getType()==0){
    			//课程
    			Map<String,Object>m1=courseDetail(String.valueOf(order.getResourceId()), String.valueOf(memberId));
    			m.put("course", m1);
    			m1=null;
    		}else if(order.getType()==1){
    			//微课
    			Map<String,Object>m1=onlineDetail(String.valueOf(order.getResourceId()), String.valueOf(memberId));
    			m.put("online", m1);
    			m1=null;
    		}else if(order.getType()==2){
    			//直播
    			Map<String,Object>m1= liveDetail(String.valueOf(order.getResourceId()), String.valueOf(memberId));
    			m.put("live", m1);
    			m1=null;
    		}
    		lm.add(m);
    		m=null;
    	}
    	
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("count", orderCount);
    	r.put("data", lm);
    	lm=null;
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //添加浏览记录
    @ApiOperation("添加浏览记录")
    @RequestMapping(value = "/saveBrowse", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "type", value = "资源类型（0-课程 1-微课 2-短片 3-网班 4-直播）", paramType = "query", dataType = "string", required = true,allowableValues = "0,1,2,3,4"),
    	@ApiImplicitParam(name = "memberId", value = "用户Id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "resourceId", value = "资源id", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils saveBrowse(@RequestParam(value="type", required=true)  String type,
    		@RequestParam(value="memberId", required=true)  Integer memberId,
    		@RequestParam(value="resourceId", required=true)  Integer resourceId) throws Exception{
    	
    	Browse browse = new Browse();
    	browse.setCreateTime(DateUtils.getDateTime());
    	browse.setMemberId(memberId);
    	browse.setResourceId(resourceId);
    	browse.setType(type);
    	Browse savebrowse = baseService.saveBrowse(browse);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,savebrowse);
    }
    //添加浏览记录
    @ApiOperation("删除浏览记录")
    @RequestMapping(value = "/delBrowse", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "id（删除单条浏览记录）", paramType = "query", dataType = "int", required = false),
    	@ApiImplicitParam(name = "memberId", value = "用户Id（删除该用户下所有浏览记录）", paramType = "query", dataType = "int", required = false)
    })
    public ApiUtils delBrowse(@RequestParam(value="id", required=false) Integer id,
    		@RequestParam(value="memberId", required=false)  Integer memberId) throws Exception{
    	
    	if(id!=null && !"".equals(id)){
    		Browse browse = publicService.findBrowse(id);
    		if(browse!=null){
    			baseService.deleteBrowse(browse);
    		}
    	}else if(memberId!=null && !"".equals(memberId)){
    		HashMap<String, Object> queryParams = new HashMap<String, Object>();
    		queryParams.put("=,memberId", memberId);
			Integer browseCount = publicService.getBrowseCount(queryParams);
			if(browseCount>0){
				List<Browse> browses = publicService.getBrowse(queryParams, 1, browseCount);
				for (Browse browse : browses) {
					baseService.deleteBrowse(browse);
				}
			}
    	}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,null);
    }
    //获取浏览记录
    @ApiOperation("获取浏览记录")
    @RequestMapping(value = "/getBrowse", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "type", value = "资源类型（0-课程 1-微课 2-短片 3-网班 4-直播）", paramType = "query", dataType = "string", required = false,allowableValues = "0,1,2,3,4"),
    	@ApiImplicitParam(name = "memberId", value = "用户Id", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getBrowse(@RequestParam(value="type", required=false)  String type,
    		@RequestParam(value="memberId", required=true)  Integer memberId,
    		@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    		@RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,memberId", memberId);
    	if(type!=null && !"".equals(type)){
    		queryParams.put("=,type", type);
    	}
    	Integer orderCount = publicService.getBrowseCount(queryParams);
    	List<Browse> browses = publicService.getBrowse(queryParams, pageNumber, pageSize);
    	List<Map<String,Object>> lm = new ArrayList<Map<String,Object>>();
    	Map<String,Object> m = null;
    	for (Browse browse : browses) {
    		m=new HashMap<String, Object>();
    		m.put("id", browse.getId());
    		m.put("createTime", browse.getCreateTime());
    		m.put("memberId", browse.getMemberId());
    		m.put("type", browse.getType());
    		m.put("resourceId", browse.getResourceId());
    		//0-课程 1-微课 2-短片 3-网班 4-直播
    		if("0".equals(browse.getType())){
    			//课程
    			Map<String,Object>m1=courseDetail(String.valueOf(browse.getResourceId()), String.valueOf(memberId));
    			m.put("course", m1);
    			m1=null;
    		}else if("1".equals(browse.getType())){
    			//微课
    			Map<String,Object>m1=onlineDetail(String.valueOf(browse.getResourceId()), String.valueOf(memberId));
    			m.put("online", m1);
    			m1=null;
    		}else if("2".equals(browse.getType())){
    			//短片
    			Map<String,Object>m1= shortFilmDetail(String.valueOf(browse.getResourceId()), String.valueOf(memberId));
    			m.put("shortFilm", m1);
    			m1=null;
    		}else if("3".equals(browse.getType())){
    			//网班
    			Map<String,Object>m1= classesOnlineDetail(String.valueOf(browse.getResourceId()), String.valueOf(memberId));
    			m.put("classesOnline", m1);
    			m1=null;
    		}else if("4".equals(browse.getType())){
    			//直播
    			Map<String,Object>m1= liveDetail(String.valueOf(browse.getResourceId()), String.valueOf(memberId));
    			m.put("live", m1);
    			m1=null;
    		}
    		lm.add(m);
    		m=null;
    	}
    	
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("count", orderCount);
    	r.put("data", lm);
    	lm=null;
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //获取消息列表
    @ApiOperation("消息列表")
    @RequestMapping(value = "/getMessage", method = RequestMethod.POST)
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "pageNumber", value = "第几页", paramType = "query", dataType = "int", required = true),
    	@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "int", required = true),
    })
    public ApiUtils getMessage(
    		@RequestParam(value="pageNumber", required=true)  Integer pageNumber,
    		@RequestParam(value="pageSize", required=true)  Integer pageSize) throws Exception{
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("^,id", "desc");
    	queryParams.put("=,status", "1");
    	Integer messageCount = publicService.getMessageCount(queryParams);
    	List<Message> messages = publicService.getMessage(queryParams, pageNumber, pageSize);
    	
    	Map<String,Object>r=new HashMap<String,Object>();
    	r.put("count", messageCount);
    	r.put("data", messages);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    //保存订单
    @ApiOperation("保存订单")
    @PostMapping("/saveOrder")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户Id",paramType = "query",  dataType = "int", required = true),
    	@ApiImplicitParam(name = "payWay", value = "支付方式（we_chat、alipay）",paramType = "query",  dataType = "string", required = false,allowableValues = "we_chat,alipay"),
    	@ApiImplicitParam(name = "status", value = "支付状态（0-支付成功 1-待支付）",paramType = "query",  dataType = "int", required = true,allowableValues = "0,1"),
    	@ApiImplicitParam(name = "payPrice", value = "实际支付金额",paramType = "query",  dataType = "string", required = false),
    	@ApiImplicitParam(name = "type", value = "类型（0-课程 1-微课 2-直播）",paramType = "query",  dataType = "int", required = true,allowableValues = "0,1,2"),
    	@ApiImplicitParam(name = "resourceId", value = "资源ID",paramType = "query",  dataType = "int", required = true),
    })
    public ApiUtils saveOrder(HttpServletRequest request,
					    		@RequestParam(value="memberId", required=true) Integer memberId,
					    		@RequestParam(value="payWay", required=false) String payWay,
					    		@RequestParam(value="status", required=true) Integer status,
					    		@RequestParam(value="payPrice", required=false) String payPrice,
					    		@RequestParam(value="type", required=true) Integer type,
					    		@RequestParam(value="resourceId", required=true) Integer resourceId) throws Exception{
    	
    	Order order = new Order();
    	
    	HashMap<String, Object> queryParams1 = new HashMap<String, Object>();
    	queryParams1.put("=,memberId", memberId);
    	queryParams1.put("=,type", type);
    	queryParams1.put("=,resourceId", resourceId);
		List<Order> orders = publicService.getOrder(queryParams1, 1, 1);
		if(orders!=null && orders.size()>0){//订单存在
			order=orders.get(0);
			if(order.getStatus()==0){//已支付状态
				return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,order);
			}
		}
		
    	
    	BigDecimal bd=new BigDecimal(0);
    	if(type==0){//课程
    		HashMap<String, Object> queryParams = new HashMap<String, Object>();
    		queryParams.put("=,courseId", resourceId);
			Integer onlineCount = publicService.getOnlineCount(queryParams );
			List<Online> onlines = publicService.getOnline(queryParams,1,onlineCount);
			queryParams=null;
			queryParams = new HashMap<String, Object>();
    		queryParams.put("=,memberId", memberId);
    		queryParams.put("=,type", "1");
    		queryParams.put("=,status", "0");
			for (Online online : onlines) {
				queryParams.put("=,resourceId", online.getId());
				Integer orderCount = publicService.getOrderCount(queryParams);
				if(orderCount!=null && orderCount>0){
					/* List<Order> order2 = publicService.getOrder(queryParams,1,1);
					 BigDecimal payPrice2 = order2.get(0).getPayPrice();
					 if(payPrice2!=null&&!"".equals(payPrice2)){
						 bd=bd.add(payPrice2);
					 }*/
				}else{
					bd=bd.add(new BigDecimal(online.getPrice()));
				}
				
			}
			
    	}
		order.setCreateIpAddress(getIpAddress(request));
		order.setCreateTime(DateUtils.getDateTime());
		order.setMemberId(memberId);
		order.setOrderNumber(String.valueOf(idWorker.nextId()));
		if(bd.compareTo(new BigDecimal(0)) == 1){
			order.setPayPrice(bd);
		}else{
			if(payPrice!=null && !"".equals(payPrice)){
				order.setPayPrice(new BigDecimal(payPrice));
			}
		}
		
		order.setPayWay(payWay);
		order.setResourceId(resourceId);
		order.setStatus(status);
		order.setType(type);
		
		Order order1=null;
		if(orders!=null && orders.size()>0){
			order1=baseService.editOrder(order);
		}else{
			order1=baseService.saveOrder(order);
		}
		
		order=null;
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,order1);
    }
    
    //编辑订单
    @ApiOperation("编辑订单")
    @PostMapping("/editOrder")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "订单Id",paramType = "query",  dataType = "int", required = true),
    	@ApiImplicitParam(name = "payWay", value = "支付方式（we_chat、alipay）",paramType = "query",  dataType = "string", required = false,allowableValues = "we_chat,alipay"),
    	@ApiImplicitParam(name = "status", value = "支付状态（0-支付成功 1-待支付）",paramType = "query",  dataType = "int", required = true,allowableValues = "0,1"),
    	@ApiImplicitParam(name = "payPrice", value = "实际支付金额",paramType = "query",  dataType = "string", required = false),
    })
    public ApiUtils editOrder(HttpServletRequest request,
    		@RequestParam(value="id", required=true) Integer id,
    		@RequestParam(value="payWay", required=false) String payWay,
    		@RequestParam(value="status", required=true) Integer status,
    		@RequestParam(value="payPrice", required=false) String payPrice) throws Exception{
    	Order order = publicService.findOrder(id);
    	Order order1 = null;
    	if(order!=null){
    		if(payPrice!=null && !"".equals(payPrice)){
    			order.setPayPrice(new BigDecimal(payPrice));
    		}
    		if(payWay!=null && !"".equals(payWay)){
    			order.setPayWay(payWay);
    		}
    		order.setStatus(status);
    		order1=baseService.editOrder(order);
    		
    		if(status==0){//如果购买成功
    			if(order.getType()==0){//这是课程，需要添加所有微客
    				HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	    		queryParams.put("=,courseId", order.getResourceId());//课程资源iD
    				Integer onlineCount = publicService.getOnlineCount(queryParams );
    				List<Online> onlines = publicService.getOnline(queryParams,1,onlineCount);//所有微客
    				for (Online online : onlines) {
    					queryParams=null;
    					queryParams = new HashMap<String, Object>();
    		    		queryParams.put("=,memberId", order.getMemberId());
    		    		queryParams.put("=,type", "1");//微客
    					queryParams.put("=,resourceId", online.getId());
    					
    					List<Order> order2 = publicService.getOrder(queryParams,1,1);//查询订单
    					if(order2!=null && order2.size()>0){//此订单存在
    						if(order2.get(0).getStatus()!=0){//此订单未付款
    							Order order3 = order2.get(0);
    							order3.setStatus(0);
    							order3.setPayPrice(new BigDecimal(online.getPrice()));
    							order3.setPayWay(payWay);
    							baseService.editOrder(order3);
    							order3=null;
    						}
    					}else{
    						Order order3 = new Order();
    						order3.setCreateIpAddress(order.getCreateIpAddress());
    						order3.setCreateTime(DateUtils.getDateTime());
    						order3.setMemberId(order.getMemberId());
    						order3.setOrderNumber(String.valueOf(idWorker.nextId()));
    						order3.setPayPrice(new BigDecimal(online.getPrice()));
    						order3.setPayWay(payWay);
    						order3.setResourceId(online.getId());
    						order3.setStatus(0);
    						order3.setType(1);
    						baseService.saveOrder(order3);
							order3=null;
    					}
    						
					}
    				queryParams=null;
    			}else if(order.getType()==1){//这是微客，需要判断是否所属课程下的微客是否全部购买
    				Online online = publicService.findOnline(order.getResourceId());//找到微客
    				Course course = publicService.findCourse(online.getCourseId());
    				if(online!=null){
    					//找到课程下所有微客
    					HashMap<String, Object> queryParams = new HashMap<String, Object>();
        	    		queryParams.put("=,courseId", online.getCourseId());//课程资源iD
        				Integer onlineCount = publicService.getOnlineCount(queryParams );
        				List<Online> onlines = publicService.getOnline(queryParams,1,onlineCount);//所有微客
        				boolean flag=true;
        				BigDecimal bd=new BigDecimal(0);
        				for (Online online2 : onlines) {
        					queryParams=null;
        					queryParams = new HashMap<String, Object>();
        		    		queryParams.put("=,memberId", order.getMemberId());
        		    		queryParams.put("=,type", "1");//微客
        					queryParams.put("=,resourceId", online2.getId());
        					queryParams.put("=,status", "0");
        					List<Order> order2 = publicService.getOrder(queryParams,1,1);//查询订单
        					if(order2==null || order2.size()<1){
        						flag=false;
        						break;
        					}else{
        						bd=bd.add(new BigDecimal(online2.getPrice()));
        					}
						}
        				if(flag){
        					Order order3 = new Order();
    						order3.setCreateIpAddress(order.getCreateIpAddress());
    						order3.setCreateTime(DateUtils.getDateTime());
    						order3.setMemberId(order.getMemberId());
    						order3.setOrderNumber(String.valueOf(idWorker.nextId()));
    						order3.setPayPrice(bd);
    						order3.setPayWay(payWay);
    						order3.setResourceId(course.getId());
    						order3.setStatus(0);
    						order3.setType(0);
    						baseService.saveOrder(order3);
							order3=null;
        				}
        				queryParams=null;
    				}
    			}
    		}
    		
    	}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,order1);
    }
    //删除订单
    @ApiOperation("删除订单")
    @PostMapping("/delOrder")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "订单Id",paramType = "query",  dataType = "int", required = true)
    })
    public ApiUtils delOrder(HttpServletRequest request, @RequestParam(value="id", required=true) Integer id) throws Exception{
    	Order order = publicService.findOrder(id);
    	if(order!=null){
    		if(order.getStatus()!=0){
    			baseService.deleteOrder(order);
    		}
    	}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,null);
    }
    //单个订单
    @ApiOperation("单个订单")
    @PostMapping("/findOrder")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户Id",paramType = "query",  dataType = "int", required = true),
    	@ApiImplicitParam(name = "type", value = "类型（0-课程 1-微课 2-直播）",paramType = "query",  dataType = "int", required = true,allowableValues = "0,1,2"),
    	@ApiImplicitParam(name = "resourceId", value = "资源ID",paramType = "query",  dataType = "int", required = true),
    })
    public ApiUtils findOrder(HttpServletRequest request, @RequestParam(value="memberId", required=true) Integer memberId,
    		 @RequestParam(value="type", required=true) Integer type,
    		 @RequestParam(value="resourceId", required=true) Integer resourceId) throws Exception{
    	Order order=new Order();
    	
    	HashMap<String, Object> queryParams = new HashMap<String, Object>();
    	queryParams.put("=,memberId", memberId);
    	queryParams.put("=,type", type);
    	queryParams.put("=,resourceId", resourceId);
		List<Order> orders = publicService.getOrder(queryParams, 1, 1);
    	if(orders!=null && orders.size()>0){
    		order=orders.get(0);
    	}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,order);
    }
  //微信支付
    @ApiOperation("微信支付")
    @PostMapping("/weChatPlay")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "body", value = "body",paramType = "query",  dataType = "string", required = true),
    	@ApiImplicitParam(name = "out_trade_no", value = "out_trade_no",paramType = "query",  dataType = "string", required = true),
    	@ApiImplicitParam(name = "total_fee", value = "total_fee",paramType = "query",  dataType = "string", required = true),
    	
    })
    public ApiUtils weChatPlay(HttpServletRequest request,
    		@RequestParam(value="body", required=true) String body,
    		@RequestParam(value="out_trade_no", required=true) String out_trade_no,
    		@RequestParam(value="total_fee", required=true) String total_fee
    		) throws Exception{
    	//String nonce_str = RandomStringUtils.random(32, true, true);
    	
    	SortedMap<Object, Object> paramMap = new TreeMap<Object, Object>();
        paramMap.put("appid",appid);//公众号ID
        paramMap.put("mch_id",mch_id);//商户号
        paramMap.put("nonce_str",RandomUtil.createRandomString(32));//32位随机字符串
        paramMap.put("body",body);//商品描述
        paramMap.put("out_trade_no",out_trade_no);//商户订单号
        paramMap.put("total_fee",total_fee);//设置交易金额 金额为分
        paramMap.put("spbill_create_ip",getIpAddress(request));//客户机IP
        paramMap.put("notify_url",notify_url);//通知地址
        paramMap.put("trade_type",trade_type);//支付方式 原生扫码
        //paramMap.put("openid", openid);//添加openid
        String sign=SignUtil.createSign(paramMap,appkey);
        //System.out.println(sign);
        paramMap.put("sign",sign);
       
        SortedMap<Object, Object>r=new TreeMap<Object, Object>();
        try {
            String rXml = new String(XmlPostUtil.sendXmlRequest(pay_url, XMLUtil.mapToXml(paramMap)));
            String return_code = (String) XMLUtil.doXMLParse(rXml).get("return_code");//得到预支付id
           
            if("SUCCESS".equals(return_code)){
            	r.put("appid", appid);
            	r.put("partnerid", mch_id);
            	//r.put("device_info", (String) XMLUtil.doXMLParse(rXml).get("device_info"));
            	//r.put("nonce_str", (String) XMLUtil.doXMLParse(rXml).get("nonce_str"));
            	//r.put("sign", (String) XMLUtil.doXMLParse(rXml).get("sign"));
            	//r.put("result_code", (String) XMLUtil.doXMLParse(rXml).get("result_code"));
            	//r.put("err_code", (String) XMLUtil.doXMLParse(rXml).get("err_code"));
            	//r.put("err_code_des", (String) XMLUtil.doXMLParse(rXml).get("err_code_des"));
            	if("SUCCESS".equals((String) XMLUtil.doXMLParse(rXml).get("result_code"))){
            		//r.put("trade_type", (String) XMLUtil.doXMLParse(rXml).get("trade_type"));
                	r.put("prepayid", (String) XMLUtil.doXMLParse(rXml).get("prepay_id"));
                	//r.put("package", "prepay_id="+(String) XMLUtil.doXMLParse(rXml).get("prepay_id"));
                	r.put("package", "Sign=WXPay");
            	}
            	r.put("timestamp", System.currentTimeMillis()/1000);
                r.put("noncestr", RandomUtil.createRandomString(32));
            	r.put("sign", SignUtil.createSign(r,appkey));
               //r.put("sign", (String) XMLUtil.doXMLParse(rXml).get("sign"));
            	//System.out.println((String) XMLUtil.doXMLParse(rXml).get("sign"));
            	
            	
            }else{
            	
            	r.put("return_msg", (String) XMLUtil.doXMLParse(rXml).get("return_msg"));
            }
            r.put("return_code", (String) XMLUtil.doXMLParse(rXml).get("return_code"));
        } catch (Exception e) {
        	r.put("return_code", "FAIL");
        	r.put("return_msg", "请求失败！");
        	r.put("err_code_des", e.getMessage());
        }
        paramMap=null;
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
  //单个订单
    @ApiOperation("单个订单")
    @PostMapping("/findOrderById")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "id", value = "id",paramType = "query",  dataType = "int", required = true)
    })
    public ApiUtils findOrderById(HttpServletRequest request, @RequestParam(value="id", required=true) Integer id) throws Exception{
    	Order order = publicService.findOrder(id);
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,order);
    }
    //单个订单
    @ApiOperation("单个订单-详情")
    @PostMapping("/findOrderDetailById")
    @ApiImplicitParams({
    	@ApiImplicitParam(name = "memberId", value = "用户Id",paramType = "query",  dataType = "int", required = true),
    	@ApiImplicitParam(name = "id", value = "id",paramType = "query",  dataType = "int", required = true)
    })
    public ApiUtils findOrderDetailById(HttpServletRequest request,
    		 @RequestParam(value="memberId", required=true) Integer memberId,
    		 @RequestParam(value="id", required=true) Integer id) throws Exception{
    	Map<String,Object>r=new HashMap<String, Object>();
    	Order order = publicService.findOrder(id);
    	r.put("order", order);
    	if(order.getStatus()==0){
    		if(order.getType()==0){//课程
    			Course course = publicService.findCourse(order.getResourceId());
    			r.put("course", course);
    			HashMap<String, Object> queryParams = new HashMap<String, Object>();
    			queryParams.put("=,courseId", course.getId());
    			Integer onlineCount = publicService.getOnlineCount(queryParams );
    			List<Online> onlines = publicService.getOnline(queryParams,1, onlineCount);
    			r.put("online", onlines);
    		}else if(order.getType()==1){//微课
    			List<Online> onlines = new ArrayList<Online>();
    			
    			Online findOnline = publicService.findOnline(order.getResourceId());
    			
    			Course course = publicService.findCourse(findOnline.getCourseId());
    			r.put("course", course);
    			
    			HashMap<String, Object> queryParams = new HashMap<String, Object>();
    			queryParams.put("=,courseId", course.getId());
    			Integer onlineCount = publicService.getOnlineCount(queryParams );
    			List<Online> onliness = publicService.getOnline(queryParams,1, onlineCount);
    			for (Online online : onliness) {
    				queryParams=null;
    				queryParams = new HashMap<String, Object>();
    				queryParams.put("=,type", "1");
    				queryParams.put("=,resourceId", online.getId());
    				queryParams.put("=,status", "0");
    				queryParams.put("=,memberId", memberId);
    				Integer orderCount = publicService.getOrderCount(queryParams);
    				if(orderCount>0){
    					onlines.add(online);
    				}
    			}
    			r.put("online", onlines);
    		}else if(order.getType()==2){//直播
    				
    			List<Live> lives = new ArrayList<Live>();
    			
    			Live findLive = publicService.findLive(order.getResourceId());
    			
    			ClassesOnline ClassesOnline = publicService.findClassesOnline(findLive.getClassesOnlineId());
    			r.put("ClassesOnline", ClassesOnline);
    			
    			HashMap<String, Object> queryParams = new HashMap<String, Object>();
    			queryParams.put("=,classesOnlineId", ClassesOnline.getId());
    			Integer liveCount = publicService.getLiveCount(queryParams );
    			List<Live> livess = publicService.getLive(queryParams,1, liveCount);
    			for (Live live : livess) {
    				queryParams=null;
    				queryParams = new HashMap<String, Object>();
    				queryParams.put("=,type", "1");
    				queryParams.put("=,resourceId", live.getId());
    				queryParams.put("=,status", "0");
    				queryParams.put("=,memberId", memberId);
    				Integer orderCount = publicService.getOrderCount(queryParams);
    				if(orderCount>0){
    					lives.add(live);
    				}
    			}
    			r.put("live", lives);
    		}
    	}
    	return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,r);
    }
    
    //上传文件
    @ApiOperation("上传文件")
    @RequestMapping(value="appUploadFile",headers="content-type=multipart/form-data",method = RequestMethod.POST)
    public ApiUtils saveSocialMain(@RequestParam(value = "file", required = true) MultipartFile file) throws Exception {
        HashMap<String,Object> data = new HashMap<String,Object>();
        String filePath = FILEPATH + "/upload/";
        if(file.getContentType().startsWith("image/")){
        	filePath += "image/";
        }else if(file.getContentType().startsWith("audio/")){
        	filePath += "audio/";
        }else if(file.getContentType().startsWith("video/")){
        	filePath += "video/";
        }else{
        	filePath += "file/";
        }
        String prefix=file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        filePath+=DateUtils.getCurrentDate()+"/"+idWorker.nextId()+prefix;
        File desFile = new File(filePath);
        if (!desFile.getParentFile().exists()) {
            desFile.mkdirs();
        }
        try {
            file.transferTo(desFile);
            if(file.getContentType().startsWith("video/")){
            	String imgepath=FILEPATH+"/upload/image/"+DateUtils.getCurrentDate()+"/"+idWorker.nextId()+".jpg";
            	VideoUtil.getVideoFirstImg(filePath, imgepath);
            	data.put("video_image",imgepath.replace(FILEPATH, "").replace(FILESERVER, "").replace("//", "/"));
            }
            data.put("data",filePath.replace(FILEPATH, "").replace(FILESERVER, "").replace("//", "/"));
        } catch (IllegalStateException | IOException e) {
            e.printStackTrace();
        }
        return new ApiUtils(ApiUtils.RESPONSE_SUCCESS,data);
    }
	private  String getIpAddress(HttpServletRequest request) {
		String ip = request.getHeader("x-forwarded-for");
		if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("X-Real-IP");
		}
		if (null == ip || 0 == ip.length() || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;
	}
	public List<Integer> getRandom10(List<Integer>list,int start, int end) {
		int num = (int) (Math.random() * (end - start + 1) + start);
		int total=10;
		if(end<10){
			total=end;
		}
		while(list.size()<total){
			if(list.contains(num)){
				num = (int) (Math.random() * (end - start + 1) + start);
			}else{
				list.add(num);
			}
		}
		return list;
	}
	public Integer getRandom(int start, int end) {
		int num = (int) (Math.random() * (end - start + 1) + start);
		return num;
	}
	
}
